<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login_con
 *
 * @author bharata
 */
class Login_con extends CI_Controller{
    //put your code here
    function __construct() {
        parent::__construct();
    }
    
    function index(){
        $this->login();
    }
    
    function login(){
        $data_login = array(
                'nama'=>"",
                'foto'=>"",
                'islogin'=>FALSE
            );
        $this->session->set_userdata($data_login);
        $this->load->view('admin/login_form');
    }
    
    function login_process(){
        $usr = $this->input->post('usr');
        $pwd = md5($this->input->post('pwd'));
        
        $str_query = 'select * from user natural join role where USERNAME="'.$usr.'" and PASSWORD="'.$pwd.'" and ID_ROLE=6';
        $result = $this->db->query($str_query);
        
        if($result->num_rows()==1){
            $data_user = $result->row_array();
            $data_login = array(
                'nama'=>$data_user['NAMA'],
                'foto'=>$data_user['FOTO'],
                'islogin'=>TRUE
            );
            $this->session->set_userdata($data_login);
            redirect(base_url().'admin/pelatihan_con');
        }else{
            redirect(base_url().'admin');
        }
    }
    
    function logout(){
        $data_login = array(
                'nama'=>"",
                'foto'=>"",
                'islogin'=>FALSE
            );
        $this->session->set_userdata($data_login);
        redirect(base_url().'admin');
    }

}